package vista;

import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

import modelo.dao.DAO;
import modelo.transfer.Socio;
import controlador.Controlador;

import javax.swing.JPasswordField;

import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class PanelModSocio extends JPanel {
	
	private DAO dao;
	private Controlador controlador;
	private JPanel actual;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_3;
	private JTextField textField_4;
	private Socio usuario;

	/**
	 * Create the panel.
	 */
	public PanelModSocio(DAO d, Controlador c, Socio ids) {
		setBackground(Color.GRAY);
		setLayout(null);
		setSize(423,250);
		this.dao = d;
		this.controlador = c;
		this.actual = this;
		this.usuario = ids;
		
		JButton btnAceptar = new JButton("Aceptar");
		btnAceptar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				modificarSocio(textField.getText(), textField_1.getText(), textField_3.getText(), textField_4.getText());
				FrameModSocUsu topFrame = (FrameModSocUsu) SwingUtilities.getWindowAncestor(actual);
				PanelSocios usu = (PanelSocios) topFrame.getPadre();
				usu.verSocios();
				topFrame.dispose();
			}
		});
		btnAceptar.setBounds(49, 187, 100, 23);
		add(btnAceptar);
		
		JButton btnCancelar = new JButton("Cancelar");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(actual);
				topFrame.dispose();
			}
		});
		btnCancelar.setBounds(277, 187, 100, 23);
		add(btnCancelar);
		
		JLabel lblDni = new JLabel("DNI:");
		lblDni.setBounds(22, 70, 46, 14);
		add(lblDni);
		
		textField = new JTextField();
		textField.setEditable(false);
		textField.setBounds(132, 67, 245, 20);
		textField.setText(this.usuario.getDni());
		add(textField);
		textField.setColumns(10);
		
		JLabel labelNombre = new JLabel("Nombre y Apellidos:");
		labelNombre.setBounds(22, 42, 100, 14);
		add(labelNombre);
		
		textField_1 = new JTextField();
		textField_1.setColumns(10);
		textField_1.setText(this.usuario.getNombre());
		textField_1.setBounds(132, 39, 245, 20);
		add(textField_1);
		
		JLabel lblDireccin = new JLabel("Direcci\u00F3n:");
		lblDireccin.setBounds(22, 98, 61, 14);
		add(lblDireccin);
		
		textField_3 = new JTextField();
		textField_3.setColumns(10);
		textField_3.setText(this.usuario.getDireccion());
		textField_3.setBounds(132, 95, 245, 20);
		add(textField_3);
		
		JLabel lblTelefono = new JLabel("Tel\u00E9fono:");
		lblTelefono.setBounds(22, 126, 46, 14);
		add(lblTelefono);
		
		textField_4 = new JTextField();
		textField_4.setColumns(10);
		textField_4.setText(this.usuario.getTelefono());
		textField_4.setBounds(132, 123, 245, 20);
		add(textField_4);
	}
	
	private void modificarSocio(String dni, String nombre, String direccion, String telefono){
		controlador.getControladorSocio().modificarSocio(dni, nombre, direccion, telefono);
	}


}
